package com.minimalist.basic.controller;

import com.minimalist.basic.config.rocketmq.producer.RocketMqProducer;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 11987
 */
@RestController
@RequestMapping("/rocketmq")
@AllArgsConstructor
public class RocketController {
    private final RocketMqProducer producer;

    @GetMapping("/sendSync/{message}")
    public ResponseEntity<String> sendSync(@PathVariable("message") String message) {
        producer.sendSyncMessage(message);
        return new ResponseEntity<>("同步消息发送成功", HttpStatus.OK);
    }

    @GetMapping("/sendAsync/{message}")
    public ResponseEntity<String> sendAsync(@PathVariable("message") String message) {
        producer.sendAsyncMessage(message);
        return new ResponseEntity<>("异步消息发送中", HttpStatus.OK);
    }

    @GetMapping("/sendOneWay/{message}")
    public ResponseEntity<String> sendOneWay(@PathVariable("message") String message) {
        producer.sendOneWayMessage(message);
        return new ResponseEntity<>("单向消息发送成功", HttpStatus.OK);

    }


    @GetMapping("/sendDelay/{message}/{delayTime}")
    public ResponseEntity<String> sendDelay(@PathVariable("message") String message
            , @PathVariable("delayTime") int delayTime) {
        producer.sendDelayMessage(message, delayTime);
        return new ResponseEntity<>("延时消息发送成功", HttpStatus.OK);
    }
}
